<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
        * @param {string} s
        * @return {number}
        */
        var lengthOfLongestSubstring = function (s) {
            let max = 0
            let charIndexMap = new Map()
            let start = 0
            for (let end = 0;end<s.length;end++){
                if (charIndexMap.has(s[end])){
                    start = Math.max(charIndexMap.get(s[end])+1,start)

                }
                charIndexMap.set(s[end],end)
                max = Math.max(max,end-start+1)
            }
            return max
        };
        // "pwwkew" -> 3

        console.log(lengthOfLongestSubstring('pwwkew'))
    </script>
</body>

</html>